<?php
/**
 * licenses : MIT
 * creatTime: 2020/5/15
 * author : weblinuxgame
 * filename: JsonApiController.php
 */

namespace App\Http\Controllers;

use App\Core\Interfaces\ResultInterface;
use App\Core\Traits\Api\ApiResponse;
use Illuminate\Http\Response;

/**
 * Class JsonApiController
 * @package App\Http\Controllers
 */
class JsonApiController extends Controller
{
    use ApiResponse;

    /**
     * 自动输出结果到请求
     * @param ResultInterface $result
     * @return Response
     */
    protected function response(ResultInterface $result): Response
    {
        if ($result->code() == 200) {
            return $this->success($result->data());
        }
        return $this->failed($result->message());
    }

}
